package cn.interceptor.action;


import java.util.Map;

import javax.interceptor.Interceptor;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import cn.mofuxiong.Model.login_register;
import cn.mofuxiong.action.Login_Register_Action;
@SuppressWarnings({ "serial", "unused" })
@InterceptorRefs({
	 @InterceptorRef("myint"),
	  @InterceptorRef("defaultStack")
})
public class InterceptorAction extends AbstractInterceptor
{
	/*在这里写入拦截过程      如果session为空并且请求的action不是登录或者注册的action  则不拦截    
	 *  如果session为空，请求的acion又不是注册或登录，则拦截下来 */
	@Override
	public String intercept(ActionInvocation arg0) throws Exception 
	{     
		ActionContext actionContext=arg0.getInvocationContext();
		@SuppressWarnings("rawtypes")
		
		HttpServletRequest req=ServletActionContext.getRequest();
		
		login_register user=(login_register)req.getSession().getAttribute("UserId");
		ActionSupport action=(ActionSupport)arg0.getAction();
		if(user!=null)
		{
			return arg0.invoke();//放行
		}else
		{
			if(action!=null&&action instanceof Login_Register_Action)
			{
				return arg0.invoke();
			}else
			{
				return "login";
			}
		}
	}


		
}
